<?php defined('SYSPATH') or die('No direct access allowed.');

class Model_File extends ORM {
    
    /*
     * Inbox belongs to message and user, 
     */ 
 
/*
    protected $_belongs_to = array(
                'message' => array('model' => 'message', 'foreign_key' => 'message_id'),
                'user'    => array('model' => 'user', 'foreign_key' => 'user_id')
    ); */
    public function path($real_name = true, $suffix = 'default', $cache_protect = false)
    {
        $name = null;
        $id = null;
        $extansion = null;
        
        if ($this->loaded())
        {                        
            $name = $this->name; 
            $id = $this->id;
            $extension = $this->extension; 
        }
        
        return Media::get_file_path($this->name, 
                                        $this->id, 
                                        $this->extension, 
                                        $real_name, 
                                        $suffix, 
                                        $cache_protect);
        
    }
    
    public function real_path($suffix = 'default') 
    {
       if ($suffix == 'default')
       {
          $suffix = '';
       }
       else
       {  
          $suffix = '_'.$suffix;
       }
       
       return UPLPATH.$this->folder.'/'.$this->id.$suffix.'.'.$this->extension;
    }
    
    public function get_animation_images()
    {
        $images_temp = DB::select(array('files.id','file_id'),
                               array('files.name','file_name'),
                               array('files.extension','file_extension'))
               ->from('desktop_items')
               ->join('files')->on('files.id', '=', 'desktop_items.icon_id')
               ->limit(24)
               ->execute(); 

        $imaqes = array();

        foreach($images_temp as $image)
        {                 
         $images[] = Media::get_file_path($image['file_name'], 
                                          $image['file_id'], 
                                          $image['file_extension'], 
                                          true);
        }

        return $images;
    }
}